<?php
namespace api\know\controller;

use api\wxapp\controller\PublicController;
use api\know\model\SentenceModel;

class SentenceController extends PublicController
{
    public function getList()
    {
        $chapter_uuid = $this->request->param('chapter_uuid', '');
        $material_uuid = $this->request->param('material_uuid', '');
        $pageNumber = $this->request->param('pageNumber', 1, 'intval');
        $pageSize = $this->request->param('pageSize', 10, 'intval');

        $s_wh[] = ['is_delete', '=', 0];
        $s_wh[] = ['is_enable', '=', 1];

        if ($chapter_uuid)
        {
            $s_wh['chapter_uuid'] = $chapter_uuid;
        }
        if ($material_uuid)
        {
            $s_wh['material_uuid'] = $material_uuid;
        }

        $total = SentenceModel::where($s_wh)->count();
        $rows = SentenceModel::where($s_wh)
                                ->field(SentenceModel::$QueryField)
                                ->page($pageNumber, $pageSize)
                                ->select();

        $this->success('请求成功!', [
            'total' => $total,
            'rows' => $rows,
        ]);
    }

}
